﻿#include "mseditmandialog.h"
#include "ui_mseditmandialog.h"
#include <QSqlQuery>

int MSeditmanDialog::ID;
MSeditmanDialog::MSeditmanDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::MSeditmanDialog)
{
    ui->setupUi(this);
    ui->frame->resize(this->geometry().width(), ui->frame->height());
    ui->status->setText("修改信息状态：");
}

MSeditmanDialog::~MSeditmanDialog()
{delete ui;}

void MSeditmanDialog::receiveD(QStringList fan)
{
//获取传递过来的数据
ID=fan.at(0).toInt();
QDate date=QDate::fromString(fan.at(1),"yyyy-MM-dd");
ui->dateEdit->setDate(date);
ui->unit->setText(fan.at(2));
ui->send->setText(fan.at(3));
ui->receiver->setText(fan.at(4));
ui->phone->setText(fan.at(5));
ui->envelope->setText(fan.at(6));
ui->copies->setText(fan.at(7));
}

void MSeditmanDialog::on_ackbtn_clicked()
{
    if(ui->send->text().isEmpty()||ui->copies->text().isEmpty()||ui->unit->text().isEmpty()){
         ui->status->setText("修改信息状态:接收日期，接收单位，接收内容，份数不能为空!");
    }else{
        QSqlQuery q;
        q.prepare("update ZZB.MaterialSend set SendDate=?,SendUnit=?,SendMan=?,Receive=?,ReceivePhone=?,Envelope=?,Copies=?  where SendID = ?");
        q.addBindValue(ui->dateEdit->text());
        q.addBindValue(ui->unit->text());
        q.addBindValue(ui->send->text());
        q.addBindValue(ui->receiver->text());
        q.addBindValue(ui->phone->text());
        q.addBindValue(ui->envelope->text());
        q.addBindValue(ui->copies->text());
        q.addBindValue(ID);
        bool ok=q.exec();
        if(ok)
        {ui->status->setText("修改信息状态:修改成功");
                this->close();}
        else{ui->status->setText("修改信息状态:修改失败");}
    }
}
